package
{
	import mx.controls.treeClasses.*;
    import flash.display.Sprite;
    import flash.events.MouseEvent;

	public class MenuRenderer extends TreeItemRenderer
	{
		[Embed(source='assets/assets.swf', symbol='level1')]
		[Bindable]
		public var level1:Class;
		
		[Embed(source='assets/assets.swf', symbol='level2')]
		[Bindable]
		public var level2:Class;

		[Embed(source='assets/assets.swf', symbol='level3')]
		[Bindable]
		public var level3:Class;
						
		[Embed(source='assets/assets.swf', symbol='level3_ico')]
		[Bindable]
		public var level3_ico:Class;
		
		[Embed(source='assets/assets.swf', symbol='plus')]
		[Bindable]
		public var plus:Class;
		
		[Embed(source='assets/assets.swf', symbol='minus')]
		[Bindable]
		public var minus:Class;
		
		public function MenuRenderer()
		{
			super ();
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
		}
        override public function set data(value:Object):void {
            super.data = value;
            if (super.listData){
              	//trace (value.@label+": "+unscaledWidth+","+value.@fontSize+","+value.@icon1+","+value.@icon2+","+value.@bg);
            	setStyle("fontSize", value.@fontSize);
           		setStyle("fontWeight", value.@fontStyle);
           		super.label.gridFitType = "pixel";
		    	super.label.antiAliasType = "advanced";
		    	
           		// disclosureIcon = branch icon
           		// icon = leaf icon
           		if (String(value.@icon1)) {
 	           		if (TreeListData(super.listData).open) {
	           			// icon2
	           			TreeListData(super.listData).disclosureIcon = this[String(value.@icon2)];
	           		} else {
	           			// icon1
	            		TreeListData(super.listData).disclosureIcon = this[String(value.@icon1)];
	           		}
           		}
           		
				if (getChildAt(0).name=="bg") {
					removeChildAt(0);
				}
				/*
           		if (String(value.@bg)) {
           			var sprite:Sprite = new this[String(value.@bg)]();
           			sprite.width = TreeListData(super.listData).owner.width+2;
           			sprite.x = -2;
           			sprite.name = "bg";
           			addChildAt(sprite, 0);
           		}
           		*/
	            //TreeListData(super.listData).hasChildren
	            //TreeListData(super.listData).owner
	            //super.data.itemIcons
	            //super.label.text
            }
        }
		
		private function mouseOverHandler(event:MouseEvent):void {
       		if (getChildAt(0).name=="bg") {
				getChildAt(0).visible = false;
			}
    	}
    	
		private function mouseOutHandler(event:MouseEvent):void {
       		if (getChildAt(0).name=="bg") {
				getChildAt(0).visible = true;
			}
    	}    	
	}
}